home *** CD-ROM | disk | FTP | other *** search
- D [0-9]
- L [a-zA-Z_]
- H [a-fA-F0-9]
- E [Ee][+-]?{D}+
- FS (f|F|l|L)
- IS (u|U|l|L)*
-
- %x COMMENT COMMENT_START SPECIAL_COMMENT
- %x CPP CPP_START
- %x CPP_INC_FILE CPP_INC_FLAGS
- %x CPP_DEFINE CPP_DEFINE_ARGP CPP_DEFINE_BODY CPP_DEFINE_ARGS
- %x GNU_EXTENSION
-
- %{
- /***************************************
- $Header: /home/amb/cxref/RCS/parse.l 1.11 1996/02/24 14:53:38 amb Exp $
-
- C Cross Referencing & Documentation tool. Version 1.0
-
- C lexical analyser
- ******************/ /******************
- Original Written by N. A. Balharrie
- CPP processing, GNU extensions and using yylval as a string Written by Andrew M. Bishop
-
- This file Copyright 1995,96 Andrew M. Bishop
- It may be distributed under the GNU Public License, version 2, or
- any higher version. See section COPYING of the GNU Public license
- for conditions under which this file may be redistributed.
- ***************************************/
-
- #include "parse-yy.h"
- #include "parse-yacc.h"
- #include "cxref.h"
- #include "memory.h"
-
- /*+ If we are in a header file then ignore the comments. +*/
- extern int in_header;
-
- /*+ Use all comments, not just those specially formatted +*/
- extern int option_all_comments;
-
- /*+ The flags and filename that comes out of GCC when a file is included. +*/
- static int inc_file_flags=0;
- static char* inc_file_name=NULL;
-
- /*+ The value of the thing that is defined (but only if it is simple). +*/
- static char* define_value=NULL;
-
- /*+ The lex state at the time that a comment is seen. +*/
- static int comment_init_state=INITIAL;
-
- /*+ To get around the GCC __extension__ keyword, pretend that it is a fuction call and skip over matched () counted by this. +*/
- static int gnu_ext_depth=0;
-
- /*+ If we see a comment immediately after a ',', ';' '};', '},' or ')' then push it before. +*/
- static int push_past=0;
-
- %}
-
- %%
-
- <*>"/*" { comment_init_state = YY_START; BEGIN(COMMENT_START); }
-
- <COMMENT_START>"*"+[ \t\n]* { BEGIN(SPECIAL_COMMENT); }
- <COMMENT_START>"+"+[ \t\n]* { BEGIN(SPECIAL_COMMENT); }
- <COMMENT_START>[*+ \t\n]*"*/" { BEGIN(comment_init_state); while(push_past) {push_past--;unput(yylval[push_past]);} }
- <COMMENT_START>[^*+] { if(option_all_comments) BEGIN(SPECIAL_COMMENT); else BEGIN(COMMENT); }
-
- <COMMENT>.|\n { }
- <COMMENT>[+*]+/"*/" { fprintf(stderr,"cxref: Warning unbalanced comment; starts simple, ends special.\n"); }
- <COMMENT>"*/" { BEGIN(comment_init_state); while(push_past) {push_past--;unput(yylval[push_past]);} }
-
- <SPECIAL_COMMENT>[ \t]+/\n { }
- <SPECIAL_COMMENT>^[ \t]+ { }
- <SPECIAL_COMMENT>[^ \t\n*+]+ { if(!in_header) SeenComment(yytext); }
- <SPECIAL_COMMENT>.|\n { if(!in_header) SeenComment(yytext); }
- <SPECIAL_COMMENT>[ \t\n]*"*"+"*/" { if(!in_header) SeenComment((char*)0);
- BEGIN(comment_init_state); while(push_past) {push_past--;unput(yylval[push_past]);} }
- <SPECIAL_COMMENT>[ \t\n]*"+"+"*/" { if(!in_header) SeenComment((char*)1);
- if(!in_header && comment_init_state==CPP_DEFINE_ARGS) SeenDefineFuncArgComment();
- if(!in_header && comment_init_state==CPP_DEFINE_BODY) SeenDefineComment();
- BEGIN(comment_init_state); while(push_past) {push_past--;unput(yylval[push_past]);} }
- <SPECIAL_COMMENT>[ \t\n]*"*/" { if(!option_all_comments)
- {
- fprintf(stderr,"cxref: Warning unbalanced comment; starts special, ends simple.\n");
- if(!in_header) SeenComment((char*)3);
- }
- else
- {
- if(!in_header) SeenComment((char*)2);
- if(!in_header && comment_init_state==CPP_DEFINE_ARGS) SeenDefineFuncArgComment();
- if(!in_header && comment_init_state==CPP_DEFINE_BODY) SeenDefineComment();
- }
- BEGIN(comment_init_state); while(push_past) {push_past--;unput(yylval[push_past]);} }
-
- [ \t]*#[ \t]* { BEGIN(CPP_START); }
-
- <CPP_START>{D}+[ \t]+"\"" { BEGIN(CPP_INC_FILE);}
- <CPP_START>define { BEGIN(CPP_DEFINE); }
- <CPP_START>[a-z]+ { BEGIN(CPP); }
-
- <CPP>. { }
- <CPP>\n { BEGIN(INITIAL); }
-
- <CPP_DEFINE>{L}({L}|{D})* { if(!in_header) SeenDefine(yytext); BEGIN(CPP_DEFINE_ARGP); }
- <CPP_DEFINE>\\\n { }
- <CPP_DEFINE>[ \t]+ { }
-
- <CPP_DEFINE_ARGP>"(" { BEGIN(CPP_DEFINE_ARGS); }
- <CPP_DEFINE_ARGP>\n { BEGIN(INITIAL); }
- <CPP_DEFINE_ARGP>[^\n(] { define_value=NULL; BEGIN(CPP_DEFINE_BODY); }
- <CPP_DEFINE_ARGP>\\\n { }
-
- <CPP_DEFINE_ARGS>{L}({L}|{D})* { if(!in_header) SeenDefineFunctionArg(yytext); }
- <CPP_DEFINE_ARGS>"," { }
- <CPP_DEFINE_ARGS>[ \t]+ { }
- <CPP_DEFINE_ARGS>\\\n { }
- <CPP_DEFINE_ARGS>")" { define_value=(char*)1; BEGIN(CPP_DEFINE_BODY); }
-
- <CPP_DEFINE_BODY>{L}({L}|{D})* { if(!in_header) {if(!define_value) define_value=CopyString(yytext); else define_value=(char*)1;} }
- <CPP_DEFINE_BODY>0[xX]{H}+{IS}? { if(!in_header) {if(!define_value) define_value=CopyString(yytext); else define_value=(char*)1;} }
- <CPP_DEFINE_BODY>0{D}+{IS}? { if(!in_header) {if(!define_value) define_value=CopyString(yytext); else define_value=(char*)1;} }
- <CPP_DEFINE_BODY>{D}+{IS}? { if(!in_header) {if(!define_value) define_value=CopyString(yytext); else define_value=(char*)1;} }
- <CPP_DEFINE_BODY>'(\\.|[^\\'])+' { if(!in_header) {if(!define_value) define_value=CopyString(yytext); else define_value=(char*)1;} }
- <CPP_DEFINE_BODY>{D}+{E}{FS}? { if(!in_header) {if(!define_value) define_value=CopyString(yytext); else define_value=(char*)1;} }
- <CPP_DEFINE_BODY>{D}*"."{D}+({E})?{FS}? { if(!in_header) {if(!define_value) define_value=CopyString(yytext); else define_value=(char*)1;} }
- <CPP_DEFINE_BODY>{D}+"."{D}*({E})?{FS}? { if(!in_header) {if(!define_value) define_value=CopyString(yytext); else define_value=(char*)1;} }
- <CPP_DEFINE_BODY>\"(\\.|[^\\"])*\" { if(!in_header) {if(!define_value) define_value=CopyString(yytext); else define_value=(char*)1;} }
- <CPP_DEFINE_BODY>. { }
- <CPP_DEFINE_BODY>\\\n { }
- <CPP_DEFINE_BODY>\n { if(define_value>(char*)1) SeenDefineValue(define_value); BEGIN(INITIAL); }
-
- <CPP_INC_FILE>[^"]+ { inc_file_name=SeenCPPFilename(yytext); }
- <CPP_INC_FILE>"\"" { inc_file_flags=0; BEGIN(CPP_INC_FLAGS); }
- <CPP_INC_FLAGS>[ \t]+{D}+ { inc_file_flags+=1<<atoi(yytext); }
- <CPP_INC_FLAGS>[ \t]*"\n" { if(inc_file_flags&6) SeenInclude(inc_file_name,inc_file_flags); BEGIN(INITIAL); }
-
-
- "auto" { yylval="auto" ; return(AUTO); }
- "break" { yylval="break" ; return(BREAK); }
- "case" { yylval="case" ; return(CASE); }
- "char" { yylval="char" ; return(CHAR); }
- "const" { yylval="const" ; return(CONST); }
- "continue" { yylval="continue"; return(CONTINUE); }
- "default" { yylval="default" ; return(DEFAULT); }
- "do" { yylval="do" ; return(DO); }
- "double" { yylval="double" ; return(DOUBLE); }
- "else" { yylval="else" ; return(ELSE); }
- "enum" { yylval="enum" ; return(ENUM); }
- "extern" { yylval="extern" ; return(EXTERN); }
- "float" { yylval="float" ; return(FLOAT); }
- "for" { yylval="for" ; return(FOR); }
- "goto" { yylval="goto" ; return(GOTO); }
- "if" { yylval="if" ; return(IF); }
- "int" { yylval="int" ; return(INT); }
- "inline" { yylval="inline" ; return(INLINE); }
- "long" { yylval="long" ; return(LONG); }
- "register" { yylval="register"; return(REGISTER); }
- "return" { yylval="return" ; return(RETURN); }
- "short" { yylval="short" ; return(SHORT); }
- "signed" { yylval="signed" ; return(SIGNED); }
- "sizeof" { yylval="sizeof" ; return(SIZEOF); }
- "static" { yylval="static" ; return(STATIC); }
- "struct" { yylval="struct" ; return(STRUCT); }
- "switch" { yylval="switch" ; return(SWITCH); }
- "typedef" { yylval="typedef" ; return(TYPEDEF); }
- "union" { yylval="union" ; return(UNION); }
- "unsigned" { yylval="unsigned"; return(UNSIGNED); }
- "void" { yylval="void" ; return(VOID); }
- "volatile" { yylval="volatile"; return(VOLATILE); }
- "while" { yylval="while" ; return(WHILE); }
-
- "__const" { yylval="const" ; return(CONST); }
- "__inline" { yylval="inline" ; return(INLINE); }
-
- "__attribute__"[ \t]+\(*[a-z]+\)* { }
-
- "__extension__" { gnu_ext_depth=0; yylval="__extension__"; BEGIN(GNU_EXTENSION); return(IDENTIFIER); }
- <GNU_EXTENSION>"(" { if(gnu_ext_depth++==0) {yylval="("; return('(');} }
- <GNU_EXTENSION>")" { if(--gnu_ext_depth==0) {yylval=")"; BEGIN(INITIAL); return(')');} }
- <GNU_EXTENSION>[^()] { }
-
- {L}({L}|{D})* { yylval=CopyString(yytext);
- if(HaveISeenType(yytext))
- return(TYPE_NAME);
- else
- return(IDENTIFIER);
- }
-
- 0[xX]{H}+{IS}? { yylval=CopyString(yytext); return(LITERAL); }
- 0{D}+{IS}? { yylval=CopyString(yytext); return(LITERAL); }
- {D}+{IS}? { yylval=CopyString(yytext); return(LITERAL); }
- '(\\.|[^\\'])+' { yylval=CopyString(yytext); return(LITERAL); }
-
- {D}+{E}{FS}? { yylval=CopyString(yytext); return(LITERAL); }
- {D}*"."{D}+({E})?{FS}? { yylval=CopyString(yytext); return(LITERAL); }
- {D}+"."{D}*({E})?{FS}? { yylval=CopyString(yytext); return(LITERAL); }
-
- \"(\\.|[^\\"])*\" { yylval=CopyString(yytext); return(STRING_LITERAL); }
-
- "..." { yylval="..."; return(ELLIPSES); }
- ">>=" { yylval=">>="; return(RIGHT_ASSIGN); }
- "<<=" { yylval="<<="; return(LEFT_ASSIGN); }
- "+=" { yylval="+="; return(ADD_ASSIGN); }
- "-=" { yylval="-="; return(SUB_ASSIGN); }
- "*=" { yylval="*="; return(MUL_ASSIGN); }
- "/=" { yylval="/="; return(DIV_ASSIGN); }
- "%=" { yylval="%="; return(MOD_ASSIGN); }
- "&=" { yylval="&="; return(AND_ASSIGN); }
- "^=" { yylval="^="; return(XOR_ASSIGN); }
- "|=" { yylval="|="; return(OR_ASSIGN); }
- ">>" { yylval=">>"; return(RIGHT_SHIFT);}
- "<<" { yylval="<<"; return(LEFT_SHIFT); }
- "++" { yylval="++"; return(INC_OP); }
- "--" { yylval="--"; return(DEC_OP); }
- "->" { yylval="->"; return(PTR_OP); }
- "&&" { yylval="&&"; return(AND_OP); }
- "||" { yylval="||"; return(OR_OP); }
- "<=" { yylval="<="; return(LE_OP); }
- ">=" { yylval=">="; return(GE_OP); }
- "==" { yylval="=="; return(EQ_OP); }
- "!=" { yylval="!="; return(NE_OP); }
- ";"[ \t]*"/*" { yylval=";\n"; push_past=2; comment_init_state = YY_START; BEGIN(COMMENT_START); }
- ";" { yylval=";"; return(';'); }
- "{" { yylval="{"; return('{'); }
- "};"[ \t]*"/*" { yylval="};\n"; push_past=3; comment_init_state = YY_START; BEGIN(COMMENT_START); }
- "},"[ \t]*"/*" { yylval="},\n"; push_past=3; comment_init_state = YY_START; BEGIN(COMMENT_START); }
- "}" { yylval="}"; return('}'); }
- ","[ \t]*"/*" { yylval=",\n"; push_past=2; comment_init_state = YY_START; BEGIN(COMMENT_START); }
- "," { yylval=","; return(','); }
- ":" { yylval=":"; return(':'); }
- "=" { yylval="="; return('='); }
- "(" { yylval="("; return('('); }
- ")"[ \t]*"/*" { yylval=")\n"; push_past=2; comment_init_state = YY_START; BEGIN(COMMENT_START); }
- ")" { yylval=")"; return(')'); }
- "[" { yylval="["; return('['); }
- "]" { yylval="]"; return(']'); }
- "." { yylval="."; return('.'); }
- "&" { yylval="&"; return('&'); }
- "!" { yylval="!"; return('!'); }
- "~" { yylval="~"; return('~'); }
- "-" { yylval="-"; return('-'); }
- "+" { yylval="+"; return('+'); }
- "*" { yylval="*"; return('*'); }
- "/" { yylval="/"; return('/'); }
- "%" { yylval="%"; return('%'); }
- "<" { yylval="<"; return('<'); }
- ">" { yylval=">"; return('>'); }
- "^" { yylval="^"; return('^'); }
- "|" { yylval="|"; return('|'); }
- "?" { yylval="?"; return('?'); }
-
- [ \t\v\n\f] { /* Ignore all white space */ }
- . { /* Ignore bad characters */ }
-
- %%
-